<?php
class Admin_Model_Cache
{

    private $cache;

    /**
     * @param int $lifetime  Default set to 30 min
     */
    function __construct($lifetime = 1800)
    {
        $frontendOpts = array(
            'caching'                 => true,
            'lifetime'                => $lifetime,
            'automatic_serialization' => true
        );
        $backendOpts  = array(
            'servers'     => array(
                array(
                    'host' => '127.0.0.1',
                    'port' => 11211
                )
            ),
            'compression' => true
        );
        $this->cache  = Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts);
    }

    function getValue($key)
    {
        return $this->cache->load($key);
    }

    function setValue($key, $value, $specificLifeTime = false)
    {
        $this->cache->save($value, $key, array(), $specificLifeTime);
    }

    function clearValue($key)
    {
        $this->cache->remove($key);
    }

    function clearAll()
    {
        $this->cache->remove(Zend_Cache::CLEANING_MODE_ALL);
    }
}
